package br.com.db;

import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

import br.com.core.Produto;


public class HibernateUtil {

private static final SessionFactory factory;
private static final ServiceRegistry registry;

static {
Configuration cf = new Configuration();

registry = new ServiceRegistryBuilder().applySettings(cf.getProperties()).build();

cf.setSessionFactoryObserver(new SessionFactoryObserver() {

/**
*
*/
private static final long serialVersionUID = 1L;

@Override
public void sessionFactoryCreated(SessionFactory arg0) {
// TODO Auto-generated method stub

	}

@Override
public void sessionFactoryClosed(SessionFactory arg0) {
// TODO Auto-generated method stub

		}
	});

cf.addAnnotatedClass(Produto.class);

factory = cf.buildSessionFactory(registry);
	}

public static SessionFactory getSessionFactory() {
return factory;
	}

}
